﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Info_ManInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            Response.Write("<script>alert('请先登录!');window.location.href='../Login.aspx'</script>");
        }
        else
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
    }
    public void Bind()
    {
        Bind b = new Bind();
        //GridView1.DataSource = b.ClassInfo();
        //GridView1.DataBind();
        DataView dv = b.studentInfo().Tables[0].DefaultView;
        PagedDataSource pds = new PagedDataSource();
        AspNetPager2.RecordCount = dv.Count;
        pds.DataSource = dv;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = AspNetPager2.CurrentPageIndex - 1;
        pds.PageSize = AspNetPager2.PageSize;
        GridView1.DataSource = pds;
        GridView1.DataBind();
        this.My.Text = "本校现共有"+pds.DataSourceCount.ToString()+"个学员";
    }
    protected void AspNetPager2_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       // if (Convert.ToInt32(Session["Purview"]) >= 5)
       // {
            int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
            SqlDelete sd = new SqlDelete();
            if (sd.DeleteStudent(id) > 0)
            {
                Bind();
            }
            else
            {
                Response.Write("<script>alert('对不起,与此有相关信息,不能删除！！')</script>");
            }
      //  }
      //  else
      //  {
      //   /   Response.Write("<script>alert('对不起,你不够权限！！')</script>");
       // }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                ((LinkButton)e.Row.Cells[9].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除学生：\"" + e.Row.Cells[0].Text + "\"吗?')");
            }
        }
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        int studentid = Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex].Value.ToString());

        //if (Convert.ToInt32(Session["Purview"]) >= 5)
       // {
            Response.Write("<script>window.open('UpdateStudentInfo.aspx?studentID=" + studentid + "','','width=320,height=230,top=250,left=280')</script>");
            Response.Write("<script>location='javascript:history.go(-1)'</script>");
       // }
       // else
       // {
       //     Response.Write("<script>alert('对不起,你不够权限！！')</script>");
       // }
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        if (this.TextBox1.Text.Trim() == "")
        {
            Response.Write("<script>alert('请输入查询条件')</script>");
        }
        else
        {
            string Input = this.TextBox1.Text;
            string Check = DropDownList1.SelectedItem.Value;
            DataTable dt = new Sqlselete().SelectStudenInfo(Check, Input);
            if (dt.Rows.Count == 0)
            {
                Response.Write("<script>alert('对不起,没有符合条件的内容！')</script>");
                Bind();
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }
    }
}
